import Vue from 'vue';
import App from '@/app.vue';
import router from '@/router/index';
import store from '@/store/index';
import iView from 'view-design';
import VueContextMenu from '@/components/contextmenu/main';
import '@/app.less';
import 'font-awesome/less/font-awesome.less';
import FormDesign from '@/components/form/index';
import '@/components/form/form.css';
import Ajax from '@/lib/ajax';
import Util from '@/lib/util';
import Config from '@/lib/config';
import Notify from '@/lib/notify';
import Modal from '@/components/ivu-modal/modal';
import {appRouters, otherRouters} from '@/router/router';
import SignalRAspNetCoreHelper from '@/lib/SignalRAspNetCoreHelper';

//此处注册系统内置表单
import BuiltInSample from '@/views/form/form-scheme/built-in/built-in-sample.vue';
import BuiltInSampleRender from '@/views/form/form-scheme/built-in/built-in-sample-render.vue';
Vue.component('BuiltInSample',BuiltInSample);
Vue.component('BuiltInSampleRender',BuiltInSampleRender);

Vue.config.productionTip = false;

Vue.use(iView);
Vue.use(VueContextMenu);
Vue.use(FormDesign)

Vue.prototype.$M = Modal;
Vue.prototype.$config = Config;



Vue.filter('formatFileSize', value => {
    return Util.formatFileSize(value);
});
Vue.filter('formatTime',value=>{
    return Util.getTime(value);
});
if (!abp.utils.getCookieValue('Abp.Localization.CultureName')) {
    let language = navigator.language;
    abp.utils.setCookieValue('Abp.Localization.CultureName', language, new Date(new Date().getTime() + 5 * 365 * 86400000), abp.appPath);
}

Ajax.get('/AbpUserConfiguration/GetAll').then(response => {
    Util.abp = Util.extend(true, Util.abp, response.data.result);
    new Vue({
        router,
        store,
        render: (h) => h(App),
        data: {
            currentPageName: '',
            busy: true,
            eventHub:new Vue(),
        },
        async mounted() {
            this.currentPageName = this.$route.name as string;
            await this.$store.dispatch({
                type: 'session/init',
            });


            if (!!this.$store.state.session.user) {
                SignalRAspNetCoreHelper.initSignalR();
            }
            console.log('session',this.$store.state.session.user.id);
            Util.abp.event.on('abp.notifications.received', userNotification => {
                this.$store.dispatch({
                    type:'notification/getUserNotifications',
                    data:{
                        maxResultCount:10,
                        skipCount:0,
                    },
                });
                this.$Notice.info({
                    title:Notify.message(userNotification).title,
                    render:Notify.message(userNotification).render,
                    duration:5,
                    name:userNotification.id,
                });
            });
            this.$store.commit('app/initCachePage');
            this.$store.commit('app/updateMenuList');
        },
        created() {
            let tagsList: any[] = [];
            appRouters.map((item) => {
                if (item.children.length <= 1) {
                    tagsList.push(item.children[0]);
                } else {
                    tagsList.push(...item.children);
                }
            });
            this.$store.commit('app/setTagsList', tagsList);
        },
    }).$mount('#app');
});


